<#import "/WEB-INF/sys/js_css.html" as js>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>角色管理</title>
</head>
<body>
	<!-- 工具条 -->
	<div id="tools" style="padding:5px;height:auto">
		<a href="javascript:void(0)" id="btn_top_add" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加角色</a>
	</div>
	<table id="datagrid" class="easyui-datagrid" data-options="singleSelect:true,fit:true,fitColumns:true,pagination:true,
		url:'${ctx}/sys/role/search',toolbar:'#tools',rownumbers : true,pageSize:15,pageList:[5,10,15,20,30]">
	    <thead>
			<tr>
				<th data-options="field:'id',hidden:true">id</th><!-- hidden -->
				<th data-options="field:'action',align:'center',width:10,formatter:formatterAction">操作</th>
				<th data-options="field:'rolename',width:60">角色名</th>
				<th data-options="field:'createUserName',align:'center',width:15">创建人</th>
				<th data-options="field:'createTime',align:'center',width:15">创建时间</th>
			</tr>
		</thead>
    </table>
    
    <!-- 角色信息div -->
	<div id="divpadd" class="easyui-window" title="角色信息添加" data-options="modal:true,collapsible:false,closed:true,minimizable:false,
		maximizable:false">
		<form id="topaddform" method="post">
			<input type="hidden" name="id" id="addid" value="" />
			<table class="table table-hover table-condensed">
				<tr>
					<td>角色名称：&nbsp;&nbsp;&nbsp;&nbsp;<input id="addrolename" name="rolename" type="text" class="easyui-validatebox" value="" /></td>
				</tr>
				<tr>
					<td align="center"><a href="javascript:void(0)" class="easyui-linkbutton" id="btn_window_top_add" iconCls="icon-save" plain="true">保存</a></td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>
<@js.easyui />
<script type="text/javascript">
jQuery(document).ready(function() {
	//添加顶级权限信息
	jQuery("#btn_top_add").click(function(){
		jQuery("#divpadd").window("open");
		jQuery("#addid").val("");
		jQuery("#addrolename").val("");
	});
	jQuery("#btn_window_top_add").click(function(){
		jQuery("#topaddform").form({
			url:"${ctx}/sys/role/add",
			onSubmit:function(){
				if(!validate())
					return false;
				var servervali = false;
				jQuery.ajax({
		   			async:false,
		   			type:"post",
		   			dataType:"json",
		   			data:{rolename:jQuery("#addrolename").val(),id:jQuery("#addid").val()},
		   			url:"${ctx}/sys/role/validate",
		   			success:function(date){
		   				if(!date.success){
		   					jQuery.messager.alert("信息",date.message,"error");
		   				}else
		   					servervali = true;
		   			}
		   		});
				return servervali;
			},
			success:function(date){
				if(!date){
					jQuery.messager.alert("信息","保存失败！","error");
					return;
				}
				jQuery.messager.alert("信息","保存成功！","info",function(){
					jQuery("#divpadd").window("close");
				});
				jQuery("#datagrid").datagrid("reload");
			}
		});
		//提交表单
		jQuery('#topaddform').submit();
	});
});
//验证表单信息
function validate(){
	if(jQuery("#addrolename").val()==""){
		jQuery.messager.alert("信息","请填写角色名称！","info");
		return false;
	}
	return true;
}
//操作单元格信息
function formatterAction(value,row,index){
	return "<img title='更改此角色' onclick='editfun(\""+row.id+"\",\""+row.rolename+"\")' src='${ctx}/js/easyui/themes/icons/pencil.png' />&nbsp;&nbsp;"+
	"<img title='删除此权限' onclick='deletefun(\""+row.id+"\")' src='${ctx}/js/easyui/themes/icons/edit_remove.png' />";
}
//修改权限信息
function editfun(id,rolename){
	jQuery("#addid").val(id);
	jQuery("#addrolename").val(rolename);
	jQuery("#divpadd").window("open");
	jQuery("#topaddform").form("clear");
}
function deletefun(id){
	jQuery.messager.confirm("信息","您确定要删除此权限？",function(arg){
		if(!arg)
			return;
		jQuery.ajax({
			async:false,
			type:"post",
			dataType:"json",
			data:{id:id},
			url:"${ctx}/sys/role/delete",
			success:function(date){
				if(!date.success){
					jQuery.messager.alert("信息","删除失败！","error");
					return;
				}
				//刷新页面
				jQuery("#datagrid").datagrid("reload");
			}
		});
	});
}
</script>